package com.awan.controller;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class StickerDetailItem {
	
	public String id;
	public String url;
	
	private static String TAG = "StickerDetailItem";
	
	public static List<StickerDetailItem> fromJsonArrayString(String jsonArrayString) {
		
		List<StickerDetailItem> result=new ArrayList<StickerDetailItem>();
		try {
			JSONObject jsonResponse = new JSONObject(jsonArrayString);
			String status = jsonResponse.getString("STATUS");
			if(status.trim().equalsIgnoreCase("SUCCESS")){
				JSONArray users = new JSONArray(jsonResponse.getString("STICKERS"));				
				for (int i=0;i<users.length();i++) {
					StickerDetailItem ui=fromJson(users.getJSONObject(i));				
					result.add(ui);
				}
			}else{
				Log.e(TAG, "STATUS "+status);
			}
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e(TAG, "JSONException[fromJsonArrayString]:"+e.getMessage());
			e.printStackTrace();
		}
		return result;
	}
	public static StickerDetailItem fromJson(JSONObject jsonObject) {
		StickerDetailItem result=null;
		try {

			result=new StickerDetailItem();				
			result.id	= jsonObject.getString("sticker_id");
			result.url	= jsonObject.getString("sticker_url");				
			
			//Log.e(TAG, "sticker_id:"+result.id);
			//Log.e(TAG, "sticker_url:"+result.url);

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e(TAG, "JSONException[fromJson]:"+e.getMessage());
			e.printStackTrace();
		}
		return result;
	}

}
